import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;

// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};

//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};


const routes = [
  {
    path: '/emp',
    name: 'emp',
    component: () => import ('../views/emp/EmpView.vue')
  },
  {
    path: '/dept',
    name: 'dept',
    component: () => import ('../views/dept/DeptView.vue')
  },
  {
    path: '/class',
    name: 'class',
    component: () => import ('../views/class/ClassView.vue')
  },
  {
    path: '/stu',
    name: 'stu',
    component: () => import ('../views/stu/StuView.vue')
  },
  {
    path: '/course',
    name: 'course',
    component: () => import ('../views/course/CourseView.vue')
  },
  {
    path: '/course-manage',
    name: 'course-manage',
    component: () => import ('../views/course-manage/CourseManageView.vue')
  },
  {
    path: '/emp-rep',
    name: 'emp-rep',
    component: () => import ('../views/emp-report/EmpReportView.vue')
  },
  {
    path: '/stu-rep',
    name: 'stu-rep',
    component: () => import ('../views/stu-report/StuReportView.vue')
  },
  {
    path: '/firstPage',
    name: 'firstPage',
    component: () => import ('../views/first-page/FirstPageView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import ('../views/login/LoginView.vue')
  },
  {
    path: '/',
    redirect: '/firstPage'
  }
]

const router = new VueRouter({
   routes
})

export default router
